﻿Module ConvertData
    ''' <summary>
    ''' Methods to convert DateTime to Unix time stamp
    ''' </summary>
    ''' <param name="_DateTime">Unix time stamp to convert</param>
    ''' <returns>Return Unix time stamp as long type</returns>
    Public Function DateTimeToUnixTimestamp(ByVal _DateTime As DateTime) As Long
        Dim _UnixTimeSpan As TimeSpan = (_DateTime.Subtract(New DateTime(1970, 1, 1, 0, 0, 0)))
        Return CLng(Fix(_UnixTimeSpan.TotalSeconds))
    End Function

    ''' <summary>
    ''' Methods to convert Unix time stamp to DateTime
    ''' </summary>
    ''' <param name="_UnixTimeStamp">Unix time stamp to convert</param>
    ''' <returns>Return DateTime</returns>
    Public Function UnixTimestampToDateTime(ByVal _UnixTimeStamp As Long) As DateTime
        Return (New DateTime(1970, 1, 1, 0, 0, 0)).AddSeconds(_UnixTimeStamp)
    End Function
End Module
